package com.ruoyi.pingjiao.service.impl;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.pingjiao.domain.Resource;
import com.ruoyi.pingjiao.domain.Teacher;
import com.ruoyi.pingjiao.mapper.ResourceMapper;
import com.ruoyi.pingjiao.mapper.TeacherMapper;
import com.ruoyi.pingjiao.service.ResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ResourceServiceImpl implements ResourceService {
    @Autowired
    private ResourceMapper resourceMapper;
    @Autowired
    private TeacherMapper teacherMapper;
    @Override
    public List<?> list(Resource resource) {
//        Long userId = SecurityUtils.getUserId();
//        if(SecurityUtils.isAdmin(userId)){
//            return resourceMapper.list(resource);
//        }
//        Teacher teacher = teacherMapper.selectTeacherByUserId(userId);
        return resourceMapper.selectListByTeacherId(resource.getCourseId());
    }

    @Override
    public int add(Resource resource) {
//        Long userId = SecurityUtils.getUserId();
//        Teacher teacher = teacherMapper.selectTeacherByUserId(userId);
//        resource.setTeacherId(Math.toIntExact(teacher.getTeacherId()));
        System.out.println(resource);
        resource.setCreateTime(new Date());
        return resourceMapper.add(resource);
    }

    @Override
    public int updateInfo(Resource resource) {
        resource.setUpdateTime(new Date());
        return resourceMapper.update(resource);
    }

    @Override
    public int delete(Integer id) {
        return resourceMapper.delete(id);
    }

    @Override
    public Object getResourceInfo(Integer id) {
        return resourceMapper.getResourceInfo(id);
    }
}
